package com.utils.wechat;

import com.bean.sqlite.api.FreeApiRandomRiddle;
import com.bean.wechat.ResultInfo;
import com.service.FreeApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class WechatStrategyRiddle implements WechatStrategy {

    @Autowired
    private FreeApiService freeApiService;

    @Override
    public void returnMsg(ResultInfo resultInfo, String content) {
        StringBuilder stringBuilder = new StringBuilder();
        //String owner = baseUtils.getBaseConfigByName("wechat_own");
        //判断是否为公众号的拥有者，如果是，则调用接口，否则返回内容
        Map map = freeApiService.addRiddle();
        if((Integer) map.get("code")==200){
            FreeApiRandomRiddle freeApiRandomRiddle = (FreeApiRandomRiddle) map.get("riddle");
            stringBuilder.append("问："+freeApiRandomRiddle.getQuestion()+"\n");
            stringBuilder.append("答："+freeApiRandomRiddle.getAnswer()+"\n");
        }else{
            stringBuilder.append("调用错误");
        }
        resultInfo.setContent(stringBuilder.toString());
        resultInfo.setReturnMethod("text");
    }
}
